/* GUI CONVERTED from rcrqmmt.p (converter v1.75) Sat Aug 12 23:00:32 2000 */
/* rcrqmmt.p - Release Management Customer Schedules                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*V8:ConvertMode=Maintenance                                            */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 8.6    LAST MODIFIED: 09/20/96           BY: TSI *K005*    */
/* REVISION: 8.6    LAST MODIFIED: 09/23/97           BY: jpm *K0J8*    */


/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb              */
         {mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rcrqmmt_p_1 " Requirement Detail Maintenance "
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

         /*INPUT PARAMETERS*/
         define input parameter schddet_recid as recid.
         define input-output parameter w_rqm_reference as character no-undo.

         /*OUTPUT VARIABLES*/
         define new shared frame b.
         define new shared variable where_we_are as integer no-undo.

         /*LOCAL VARIABLES*/
         define shared variable global_recid as recid.
         define shared variable window_recid as recid.
         define variable i as integer no-undo.
         define variable w_ref as character no-undo.
         define variable rqmdet_recid as recid no-undo.
         define variable hrqmdet_recid as recid no-undo.
         define variable errors as logical no-undo.
         define variable yn as logical no-undo.

         /* BUFFERS */
         define buffer b_schd for schd_det.

         /*V8:EditableDownFrame=b */
         FORM /*GUI*/ 
/*K0J8*/ /* rqm_cat */
/*K0J8*/   rqm_det.rqm_cat
           rqm_value
             with frame b title color normal
             (getFrameTitle("REQUIREMENT_DETAIL_MAINTENANCE",42))
               width 80 8 down scroll 1 no-validate THREE-D /*GUI*/.


               /* SET EXTERNAL LABELS */
               setFrameLabels(frame b:handle).

         find schd_det
            where recid(schd_det) = schddet_recid
            no-lock.

         find sod_det
            where sod_nbr = schd_nbr
              and sod_line = schd_line
            no-lock.

         find so_mstr
            where so_nbr = schd_nbr
            no-lock.

         ststatus = stline[2].
         status input ststatus.

         mainloop:
         do transaction with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

            clear frame b all no-pause.
            view frame b.

            if schd_reference <> ""
               and schd_type = 3
               and not can-find(first rqm_det
                  where rqm_type      = schd_type
                    and rqm_nbr       = schd_nbr
                    and rqm_line      = schd_line
                    and rqm_rlse_id   = schd_rlse_id
                    and rqm_date      = schd_date
                    and rqm_time      = schd_time
                    and rqm_interval  = schd_interval
                    and rqm_reference = schd_reference
/*K0J8*/ /*         and rqm_cat       = "AUTHNBR") then  */
/*K0J8*/    and rqm_det.rqm_cat       = "AUTHNBR") then
            do:
               {gprun.i ""rcrqmmta.p"" "(input ""AUTHNBR"",
                                         input schd_reference,
                                         input schddet_recid,
                                         output rqmdet_recid,
                                         output errors")}
/*GUI*/ if global-beam-me-up then undo, leave.


               if errors then
               do:
                  w_rqm_reference = "".

                  pause.
                  undo, retry.
               end.

            end. /* if not can-find */

            find first rqm_det
               where rqm_type      = schd_type
                 and rqm_nbr       = schd_nbr
                 and rqm_line      = schd_line
                 and rqm_rlse_id   = schd_rlse_id
                 and rqm_date      = schd_date
                 and rqm_time      = schd_time
                 and rqm_interval  = schd_interval
                 and rqm_reference = schd_reference
               exclusive-lock no-error.

            i = 0.
            do while i < frame-down and available rqm_det:
               display
/*K0J8*/   /*     rqm_cat      */
/*K0J8*/          rqm_det.rqm_cat
                  rqm_value.

               i = i + 1.
               if i < frame-down then down 1.

               find next rqm_det
                  where rqm_type      = schd_type
                    and rqm_nbr       = schd_nbr
                    and rqm_line      = schd_line
                    and rqm_rlse_id   = schd_rlse_id
                    and rqm_date      = schd_date
                    and rqm_time      = schd_time
                    and rqm_interval  = schd_interval
                    and rqm_reference = schd_reference
                  exclusive-lock no-error.
            end. /* do while i */

            up frame-line - 1.

            find first rqm_det
               where rqm_type      = schd_type
                 and rqm_nbr       = schd_nbr
                 and rqm_line      = schd_line
                 and rqm_rlse_id   = schd_rlse_id
                 and rqm_date      = schd_date
                 and rqm_time      = schd_time
                 and rqm_interval  = schd_interval
                 and rqm_reference = schd_reference
               exclusive-lock no-error.

            detail-loop:
            repeat with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

               display
/*K0J8*/ /*       if available rqm_det then rqm_cat else " " @ rqm_cat */
/*K0J8*/          if available rqm_det then rqm_det.rqm_cat
/*K0J8*/          else " " @ rqm_det.rqm_cat
                  if available rqm_det then rqm_value else " " @ rqm_value.

/*K0J8*/ /*    prompt-for rqm_cat rqm_value */
/*K0J8*/       prompt-for rqm_det.rqm_cat rqm_value
               go-on(F5 F9 F10 CTRL-D CURSOR-UP CURSOR-DOWN)

               editing:
                  readkey.

                  /**************************************************/
                  /* END-ERROR                                      */
                  /**************************************************/
                  if keyfunction(lastkey) = "END-ERROR"
                     and schd_type = 3 then
                  do:
                     rqmdet_recid = if available rqm_det
                                       then recid(rqm_det) else ?.

                     find first rqm_det
                        where rqm_type      = schd_type
                          and rqm_nbr       = schd_nbr
                          and rqm_line      = schd_line
                          and rqm_rlse_id   = schd_rlse_id
                          and rqm_date      = schd_date
                          and rqm_time      = schd_time
                          and rqm_interval  = schd_interval
                          and rqm_reference = schd_reference
/*K0J8*/ /*               and rqm_cat       = "AUTHNBR" */
/*K0J8*/          and rqm_det.rqm_cat       = "AUTHNBR"
                        no-lock no-error.

                     hrqmdet_recid = if available rqm_det
                                       then recid(rqm_det) else ?.

                     if available rqm_det then
                        find next rqm_det
                           where rqm_type      = schd_type
                             and rqm_nbr       = schd_nbr
                             and rqm_line      = schd_line
                             and rqm_rlse_id   = schd_rlse_id
                             and rqm_date      = schd_date
                             and rqm_time      = schd_time
                             and rqm_interval  = schd_interval
                             and rqm_reference = schd_reference
/*K0J8*/ /*                  and rqm_cat       = "AUTHNBR" */
/*K0J8*/             and rqm_det.rqm_cat       = "AUTHNBR"
                           no-lock no-error.

                     if available rqm_det then
                     do on endkey undo, retry:
                        {mfmsg.i 1511 3}
                        pause.

                        find rqm_det
                           where recid(rqm_det) = rqmdet_recid
                           exclusive-lock no-error.

                        next detail-loop.

                     end. /* if available rqm_det */

                     find rqm_det
                        where recid(rqm_det) = hrqmdet_recid
                        no-lock no-error.

                     if available rqm_det
                        and rqm_value ne w_rqm_reference then
                     do on endkey undo, retry:
                        yn = yes.
                        {mfmsg01.i 1510 1 yn}

                        if yn then
                        do:
                           if can-find(b_schd
                              where b_schd.schd_type =
                                       schd_det.schd_type
                                and b_schd.schd_nbr =
                                       schd_det.schd_nbr
                                and b_schd.schd_line =
                                       schd_det.schd_line
                                and b_schd.schd_rlse_id =
                                       schd_det.schd_rlse_id
                                and b_schd.schd_date =
                                       schd_det.schd_date
                                and b_schd.schd_time =
                                       schd_det.schd_time
                                and b_schd.schd_interval =
                                       schd_det.schd_interval
                                and b_schd.schd_reference = rqm_value) then
                           do:
                              /* DUPLICATE SCHD_DET WOULD RESULT */
                              {mfmsg.i 1526 3}
                              undo, retry.
                           end.

                           w_ref = rqm_value.

                           for each rqm_det
                              where rqm_type      = schd_type
                                and rqm_nbr       = schd_nbr
                                and rqm_line      = schd_line
                                and rqm_rlse_id   = schd_rlse_id
                                and rqm_date      = schd_date
                                and rqm_time      = schd_time
                                and rqm_interval  = schd_interval
                                and rqm_reference = schd_reference
/*K0J8*/ /*                     and rqm_cat       = "AUTHNBR" */
/*K0J8*/                and rqm_det.rqm_cat       = "AUTHNBR"
                              exclusive-lock:

                              rqm_reference = w_ref.
                           end. /* for each rqm_det */

                           w_rqm_reference = w_ref.

                           return.

                        end. /* if yn */
                        else
                        do:
                           find rqm_det
                              where recid(rqm_det) = rqmdet_recid
                              exclusive-lock no-error.

                           next detail-loop.
                        end.

                     end. /* if rqm_value ne w_rqm_reference */
                     else
                     if not available rqm_det
                        and can-find(b_schd
                           where b_schd.schd_type =
                                    schd_det.schd_type
                             and b_schd.schd_nbr =
                                    schd_det.schd_nbr
                             and b_schd.schd_line =
                                    schd_det.schd_line
                             and b_schd.schd_rlse_id =
                                    schd_det.schd_rlse_id
                             and b_schd.schd_date =
                                    schd_det.schd_date
                             and b_schd.schd_time =
                                    schd_det.schd_time
                             and b_schd.schd_interval =
                                    schd_det.schd_interval
                             and b_schd.schd_reference =  ""
                             and recid(b_schd) <> recid(schd_det)) then
                     do:
                        /* DUPLICATE SCHD_DET WOULD RESULT */
                        {mfmsg.i 1526 3}
                        undo, retry.
                     end.
                     else
                     if not available rqm_det then
                        w_rqm_reference = "".

                  end. /* if "END-ERROR" */

                  apply lastkey.
               end. /* editing */

               if (lastkey = keycode("F9")
                  or lastkey = keycode("CURSOR-UP")
                  or lastkey = keycode("F10")
                  or lastkey = keycode("CURSOR-DOWN")
                  or lastkey = keycode("F5")
                  or lastkey = keycode("CTRL-D")) then
               do on endkey undo, leave detail-loop:

                  display
/*K0J8*/ /*          if available rqm_det then rqm_cat else " " @ rqm_cat */
/*K0J8*/             if available rqm_det then rqm_det.rqm_cat
/*K0J8*/             else " " @ rqm_det.rqm_cat
                     if available rqm_det then rqm_value else " " @ rqm_value.

                  pause 0.

                  /***************************************************/
                  /* CURSOR-UP                                       */
                  /***************************************************/
                  if lastkey = keycode("F9")
                     or lastkey = keycode("CURSOR-UP") then
                  do:
                     find prev rqm_det
                        where rqm_type      = schd_type
                          and rqm_nbr       = schd_nbr
                          and rqm_line      = schd_line
                          and rqm_rlse_id   = schd_rlse_id
                          and rqm_date      = schd_date
                          and rqm_time      = schd_time
                          and rqm_interval  = schd_interval
                          and rqm_reference = schd_reference
                        exclusive-lock no-error.

                     if available rqm_det then
                        up 1.
                     else
                     do:
                        {mfmsg.i 21 1}
                        find first rqm_det
                           where rqm_type      = schd_type
                             and rqm_nbr       = schd_nbr
                             and rqm_line      = schd_line
                             and rqm_rlse_id   = schd_rlse_id
                             and rqm_date      = schd_date
                             and rqm_time      = schd_time
                             and rqm_interval  = schd_interval
                             and rqm_reference = schd_reference
                           exclusive-lock no-error.
                     end.
                  end. /* if CURSOR-UP */

                  /***************************************************/
                  /* CURSOR-DOWN                                     */
                  /***************************************************/
                  else
                  if lastkey = keycode("F10")
                     or lastkey = keycode("CURSOR-DOWN") then
                  do:
                     find next rqm_det
                        where rqm_type      = schd_type
                          and rqm_nbr       = schd_nbr
                          and rqm_line      = schd_line
                          and rqm_rlse_id   = schd_rlse_id
                          and rqm_date      = schd_date
                          and rqm_time      = schd_time
                          and rqm_interval  = schd_interval
                          and rqm_reference = schd_reference
                        exclusive-lock no-error.

                     if available rqm_det then
                        down 1.
                     else
                     do:
                        {mfmsg.i 20 1}
                        find last rqm_det
                           where rqm_type      = schd_type
                             and rqm_nbr       = schd_nbr
                             and rqm_line      = schd_line
                             and rqm_rlse_id   = schd_rlse_id
                             and rqm_date      = schd_date
                             and rqm_time      = schd_time
                             and rqm_interval  = schd_interval
                             and rqm_reference = schd_reference
                           exclusive-lock no-error.
                     end.
                  end. /* if CURSOR-DOWN */

                  /***************************************************/
                  /* DELETE                                          */
                  /***************************************************/
                  else
                  if (lastkey = keycode("F5")
                     or lastkey = keycode("CTRL-D"))
                     and available rqm_det then
                  do on endkey undo, retry:

                     /***********************************************/
                     /* CHECK FOR LINKS TO CONFIRMED AND UNCONFIRMED*/
                     /* SHIPPERS.                                   */
                     /***********************************************/
                     {gprun.i ""rcscmtc.p""
                        "(input recid(schd_det),
                          output errors)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                     if errors then
                        next detail-loop.

                     yn = yes.
                     {mfmsg01.i 11 1 yn}
                     if not yn then
                        next detail-loop.

                     delete rqm_det.

                     where_we_are = frame-line.

                     find next rqm_det
                        where rqm_type      = schd_type
                          and rqm_nbr       = schd_nbr
                          and rqm_line      = schd_line
                          and rqm_rlse_id   = schd_rlse_id
                          and rqm_date      = schd_date
                          and rqm_time      = schd_time
                          and rqm_interval  = schd_interval
                          and rqm_reference = schd_reference
                        no-lock no-error.

                     if available rqm_det then
                     do:
                        rqmdet_recid = recid(rqm_det).

                        display
/*K0J8*/ /*                rqm_cat */
/*K0J8*/                   rqm_det.rqm_cat
                           rqm_value.

                        do i = where_we_are to frame-down - 1:
                           down 1.
                           find next rqm_det
                              where rqm_type      = schd_type
                                and rqm_nbr       = schd_nbr
                                and rqm_line      = schd_line
                                and rqm_rlse_id   = schd_rlse_id
                                and rqm_date      = schd_date
                                and rqm_time      = schd_time
                                and rqm_interval  = schd_interval
                                and rqm_reference = schd_reference
                              no-lock no-error.

                           if available rqm_det then
                           do:
                              display
/*K0J8*/ /*                      rqm_cat */
/*K0J8*/                         rqm_det.rqm_cat
                                 rqm_value.
                           end.
                           else
                           do:
                              display
/*K0J8*/ /*                      "" @ rqm_cat */
/*K0J8*/                         "" @ rqm_det.rqm_cat
                                 "" @ rqm_value.
                           end.
                        end. /* do i = where_we_are */

                        up frame-down - where_we_are.
                        find rqm_det
                           where recid(rqm_det) = rqmdet_recid
                           exclusive-lock.
                     end. /* if available rqm_det */
                     else
                     do:
                        display
/*K0J8*/ /*                "" @ rqm_cat */
/*K0J8*/                   "" @ rqm_det.rqm_cat
                           "" @ rqm_value.

                        find prev rqm_det
                           where rqm_type      = schd_type
                             and rqm_nbr       = schd_nbr
                             and rqm_line      = schd_line
                             and rqm_rlse_id   = schd_rlse_id
                             and rqm_date      = schd_date
                             and rqm_time      = schd_time
                             and rqm_interval  = schd_interval
                             and rqm_reference = schd_reference
                           exclusive-lock no-error.

                        if available rqm_det then
                           up 1.
                     end. /* not available rqm_det */
                  end. /* DELETE */
               end. /* do on endkey */

               /*********************************************************/
               /* DATA ENTRY VALIDATION                                 */
               /*********************************************************/
               else
/*K0J8*/ /*    if rqm_cat entered or rqm_value entered then */
/*K0J8*/       if rqm_det.rqm_cat entered or rqm_value entered then
               do:
/*K0J8*/ /*       {gprun.i ""rcrqmmta.p"" "(input (input rqm_cat), */
/*K0J8*/          {gprun.i ""rcrqmmta.p"" "(input (input rqm_det.rqm_cat),
                                           input (input rqm_value),
                                           input schddet_recid,
                                           output rqmdet_recid,
                                           output errors")}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if errors then
                     undo, retry.

                  find rqm_det
                     where recid(rqm_det) = rqmdet_recid
                     exclusive-lock no-error.

               end. /* if rqm_cat entered */
            end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* detail-loop */

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* mainloop */

         hide frame b no-pause.
